package com.example.course_mangger_system.controller;

import com.example.course_mangger_system.entity.Student;
import com.example.course_mangger_system.service.StudentService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 学生
 * @author: hyj
 * @date: 2023/11/25 15:53
 */
@RestController
@RequestMapping("/student")
public class StudentController {

    @Resource
    private StudentService studentService;

    /**
     * 添加
     *
     * @param student
     * @return
     */
    @PostMapping("/save")
    public int save(@RequestBody Student student) {

        return studentService.save(student);
    }

    /**
     * 删除
     *
     * @param student
     * @return
     */
    @PostMapping("/delete")
    public int delete(@RequestBody Student student) {
        if (student.getStuNo() == null) {
            return 0;
        }
        return studentService.delete(student.getStuNo());
    }

    /**
     * 修改
     *
     * @param student
     * @return
     */
    @PostMapping("/update")
    public int update(@RequestBody Student student) {
        if (student.getStuNo() == null) {
            return 0;
        }
        return studentService.update(student);
    }

    /**
     * 查询
     *
     * @param student
     * @return
     */
    @PostMapping("/list")
    public List<Student> list(@RequestBody Student student) {
        return studentService.list(student);
    }


    @PostMapping("/getById")
    public Student getById(@RequestBody Student student) {
        if (student.getStuNo() == null) {
            return null;
        }
        return studentService.getById(student.getStuNo());
    }
}
